<form id="form_item" method="post" enctype="multipart/form-data" action="{:U('Task/'.($taskData?'edit':'add'))}">
	<if condition="$taskData">
	<input type="hidden" name="id" value="{$taskData['id']}" />
	</if>
	<input type="hidden" name="rule_id" value="" />
    <div class="form-group">
        <label>{$Think.lang.task_name}</label>
        <input name="name" class="form-control" value="{$taskData['name']}">
    </div>
    <div class="form-group">
        <label>{$Think.lang.task_tg}</label>
        {$tgSelect}
    </div>
    <div class="form-group">
        <label>{$Think.lang.task_module}</label>
        <div class="input-group" style="width:100%;">
	        <select name="module" class="form-control">
	        	<foreach name="Think.config.ALLOW_COLL_MODULES" item="cmodule">
	           	<option value="{$cmodule}">{:L('task_module_'.$cmodule)}</option>
	        	</foreach>
	        </select>
	        <div class="input-group-btn dropdown">
			  <button class="btn btn-default dropdown-toggle" type="button" id="btn_import_rule" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
			   	导入规则
			  	<span class="caret"></span>
			  </button>
			  <ul class="dropdown-menu dropdown-menu-right dropdown-import-rule" aria-labelledby="btn_import_rule">
			  	<li><a href="javascript:;" onclick="windowModal('导入规则会覆盖该任务的采集器设置，且不可恢复','{:U("Mystore/collect?tpl=task")}');">已下载规则</a></li>
			  	<li><a href="javascript:;" onclick="windowModal('导入规则会覆盖该任务的采集器设置，且不可恢复','{:U("Collector/list?module=pattern&tpl=task")}');">其它任务的规则</a></li>
			  	<li role="separator" class="divider"></li>
			  	<li style="padding-left:20px;padding-bottom:5px;"><input type="file" name="rule_file" /></li>
			  </ul>
			</div>
		</div>
    </div>
    <div class="form-group">
        <label>{$Think.lang.task_auto}</label>
        <div class="input-group">
        	<label class="radio-inline"><input type="radio" name="auto" value="1">{$Think.lang.yes}</label>
        	<label class="radio-inline"><input type="radio" name="auto" value="0">{$Think.lang.no}</label>
        </div>
    </div>
   	<div class="form-group">
       	<label>{$Think.lang.task_sort}</label>
		<input type="text" class="form-control" name="sort" autocomplete="off" value="{$taskData['sort']|intval}" />
		<p class="help-block">{$Think.lang.task_sort_help}</p>
	</div>
   	<div class="form-group">
		<button type="submit" class="btn btn-primary btn-block">{$Think.lang.save}</button>
	</div>
	<include file="Task:stepsbar" />
</form>
<script type="text/javascript">
<if condition="!empty($taskData)">
	$('#form_item select[name="tg_id"]').val("{$taskData['tg_id']|intval}");
	$('#form_item select[name="auto"]').val("{$taskData['auto']|intval}");
	$('#form_item select[name="module"]').val("{$taskData['module']}");
	$('#form_item input[name="auto"][value="{$taskData["auto"]|intval}"]').attr('checked','checked');
</if>
//模块显示导入
$('#form_item select[name="module"]').bind('change',function(){
	if($(this).val()!='pattern'){
		$('#btn_import_rule').parents('.input-group-btn').hide();
	}else{
		$('#btn_import_rule').parents('.input-group-btn').show();
	}
});
//导入本地规则
$('#form_item [name="rule_file"]').bind('change',function(){
	import_rule('file',$(this).val());
	$(this).parents('.dropdown').removeClass('open');
});
//导入规则
function import_rule(ruleId,ruleName){
	$('#form_item input[name="rule_id"]').val(ruleId);
	$('#btn_import_rule').text('导入规则：'+ruleName);
	if(ruleId!='file'){
		//不是文件规则
		$('#form_item [name="rule_file"]').val('');
	}
	$('#myModal').modal('hide');
}
</script>